<?php
/*
 * Created on Apr 16, 2012
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
?>
<script type="text/javascript">
$(document).ready(function(){
	var aDOB = $("#playerdob").val().split("/");
	if(aDOB.length == 3){
		$("#dobMonth").val(parseInt(aDOB[1]));
		$("#dobYear").val(parseInt(aDOB[0]))
		setDates();
		$("#dobDate").val(parseInt(aDOB[2]));
	}
	else{
		setDates();
	}
	
	$("#profileForm").submit(function(){return formVal();});
	
});

function setDates(){

	var oMonth = parseInt($("#dobMonth").val());
	var oYear = parseInt($("#dobYear").val());
	var aShortM = [2,4,6,9,11];
	var maxDay = 31;
	
	if(oMonth == 2){
		maxDay = ((oYear % 4) > 0)?28:29;
	}
	else if(jQuery.inArray(oMonth,aShortM) > -1){
		maxDay = 30;
	}
	
	$("#dobDate >option").remove();
	
	var oOptDates = $("#dobDate");
	for(var i=1;i<=maxDay;i++){
		oOptDates.append($("<option/>").val(i).text(i));
	}
}

function formVal(){
	var aErrors = new Array();
	
	
	if($("#txtBxFirstName").val() == "")
		aErrors.push("- First name must not be blank.");
		
	if($("#txtBxLastName").val() =="")
		aErrors.push("- Last name must not be blank.");

	if($("#txtBxLastName").val() =="")
		aErrors.push("- Email address must not be blank.");

	if($("#taBio").val().length > 1000)
        aErrors.push("- BIO section must be under 1000 characters. You inputted " + $("#taBio").val().length + "."); 

	var sErrorMsg = aErrors.join("\n");

	if(sErrorMsg != "")
		alert(sErrorMsg);
		
	return (!(sErrorMsg != ""));
}

</script>
<form id="profileForm" name="profileForm" action="index.php" method="POST">
<?php 
	printf("<input type=\"hidden\" id=\"playerid\" name=\"playerid\" value=\"%s\">",$playerid);
	printf("<input type=\"hidden\" id=\"playerdob\" name=\"playerdob\" value=\"%s\">",(isset($player->dob) && $player->dob != null)?date("Y/m/d",strtotime($player->dob)):"");
	if(isset($_GET[AdminItemEnum::PLAYER_MGMT])){
		printf("<input type=\"hidden\" id=\"%s\" name=\"%s\" value=\"1\">",AdminItemEnum::PLAYER_MGMT,AdminItemEnum::PLAYER_MGMT);	
	}
?>
<table cellpadding="0" cellspacing="0" border="0" width="100%" style="margin-top:10px">
	<tr>
		<td align="right" width="10%">Name:</td>
		<td>
			<div style="float:left">
			<span style="font-size:10px;">First name</span><br/>
			<input type="text" id="txtBxFirstName" name="txtBxFirstName" value="<?php printf("%s",isset($player->firstName)?$player->firstName:"")?>" maxlength="25"/>
			</div>
			<div style="float:left">
				<span style="font-size:10px;">Last name</span><br/>
			<input type="text" id="txtBxLastName" name="txtBxLastName" value="<?php printf("%s",isset($player->lastName)?$player->lastName:"")?>" maxlength="25"/>
			</div>
		</td>
	</tr>
	<tr>
		<td align="right" width="10%">Email address:</td>
		<td><input type="text" id="txtBxEmailAddr" name="txtBxEmailAddr" value="<?php printf("%s",isset($player->emailAddress)?$player->emailAddress:"")?>" maxlength="100"/></td>
	</tr>
	<tr>
		<td align="right">DOB:</td>
		<td>
			<select id="dobMonth" name="dobMonth" onchange="setDates();">
				<?php
				for($i=1;$i<13;$i++){
					printf("<option value=\"%s\">%s</option>",$i,strftime("%b",strtotime("2011/".$i."/01")));
				}
				?>
			</select>
			<select id="dobDate" name="dobDate"></select>
			<select id="dobYear" name="dobYear" onchange="setDates();">
				<?php
				for($i=1950;$i<=2030;$i++){
					printf("<option value=\"%s\">%s</option>",$i,$i);
				}
				?>
			</select>
		</td>
	</tr>
	<tr>
		<td align="right">Hometown:</td>
		<td><input type="text" id="txtBxNativeTown" name="txtBxNativeTown" value="<?php printf("%s",isset($player->homeTown)?$player->homeTown:"");?>" maxlength="50"/></td>
	</tr>
	<tr>
		<td align="right">Currently city:</td>
		<td><input type="text" id="txtBxCurrentCity" name="txtBxCurrentCity" value="<?php printf("%s",isset($player->currentCity)?$player->currentCity:"");?>" maxlength="50"/></td>
	</tr>
	<tr>
		<td align="right">Verified:</td>
		<td><input type="checkbox" id="chkBxVerified" name="chkBxVerified" value="1"<?php echo ($player->verified)?" checked":"";?>/></td>
	</tr>
	<tr>
		<td align="right">Locked:</td>
		<td><input type="checkbox" id="chkBxLocked" name="chkBxLocked" value="1"<?php echo ($player->locked)?" checked":"";?>/></td>
	</tr>
	<tr>
		<td align="right">Is Admin:</td>
		<td><input type="checkbox" id="chkBxIsAdmin" name="chkBxIsAdmin" value="1"<?php echo ($player->admin)?" checked":"";?>/></td>
	</tr>
	<tr>	
		<td align="right">Bio:</td>
		<td>
			<textarea id="taBio" name="taBio" rows="6" cols="70"><?php printf("%s",isset($player->bio)?$player->bio:"");?></textarea>
		</td>
	</tr>
	<tr>
		<td align="center" colspan="2">
			<input type="button" value="Cancel" onclick="history.go(-1)"/>
			<input type="submit" name="btnSaveProfile" value="Save"/>
		</td>
	</tr>
</table>
</form>